package Windows;

import java.awt.CardLayout;
import java.awt.Image;

import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import GroupWare.ShareRoot;
import Tools.IMG;
import Windows.DownLoads.ShowDownloadPanel;
import Windows.Search.SeachTabbedPane;
import Windows.Share.ResShareTable;
import Windows.Tree.ResTree;
import Windows.Tree.TreeNodePic;

public class MainPanel extends PicPanel implements TreeSelectionListener {
	private CardLayout cl = new CardLayout(2, 2);
	private SeachTabbedPane seachp;// 搜索面板
	private ShowDownloadPanel downp;// 下载面板
	private ResShareTable resp;// 共享面板
	private PicPanel leavep;// 留言面
	private PicPanel tops;// 排行榜
//	private MyPanel about;// 好友面板

	public MainPanel(Image imgPath, ResToolBar rtb, TreeNodePic mn, ResTree tree, ShareRoot sp) {
		super(imgPath);
		this.setLayout(cl);
		downp = new ShowDownloadPanel(tree, sp);
		seachp = new SeachTabbedPane(downp, rtb);
		resp = new ResShareTable();
//		fellowp = new MyPanel("Skin/dlg_ftr_yellow.png");
		leavep = new PicPanel(IMG.RED);
		tops = new PicPanel(IMG.BLACK);
//		about = new MyPanel("Skin/index-top.jpg");
		this.add(seachp, "搜索资源");
		this.add(downp, "正在下载");
		this.add(resp, "共享目录");
//		this.add(fellowp, "我的好友");
		this.add(leavep, "留言板");
		this.add(tops, "最新排行");
//		this.add(about, "关于");

		mn.add(seachp.getTreeNode());
		mn.add(downp.getTreeNode());
		mn.add(resp.getTreeNode());
		mn.add(leavep.getTreeNode());
		mn.add(tops.getTreeNode());
//		mn.add(about.getTreeNode());

		cl.show(this, "搜索资源");
	}

	public ShowDownloadPanel getDownp() {
		return downp;
	}

	public PicPanel getLeavep() {
		return leavep;
	}

	public ResShareTable getResp() {
		return resp;
	}

	public SeachTabbedPane getSeachp() {
		return seachp;
	}

//	public MyPanel getFellowp() {
//		return fellowp;
//	}

//	public MyPanel getAbout() {
//		return about;
//	}

	@Override
	public void valueChanged(TreeSelectionEvent tse) {
		// TODO Auto-generated method stub
		// --树形框现行选中项被改变
//		JTree jt = (JTree)tse.getSource();
//		TreeSelectionModel tsm = jt.getSelectionModel();
		String str = tse.getPath().toString();
		if (str.startsWith("[ResShare, 搜索资源")) {
			cl.show(this, "搜索资源");// 显示相应Panel
			JTree tree = (JTree) tse.getSource();
			int index = tree.getLeadSelectionRow() - 2;
			if (seachp.getComponentCount() > 0 && index >= 0)
				seachp.setSelectedIndex(index);
		} else if (str.startsWith("[ResShare, 正在下载")) {
			cl.show(this, "正在下载");// 显示相应Panel
		} else if (str.startsWith("[ResShare, 共享目录")) {
			cl.show(this, "共享目录");// 显示相应Panel
		} else if (str.startsWith("[ResShare, 我的好友")) {
			cl.show(this, "我的好友");// 显示相应Panel
		} else if (str.startsWith("[ResShare, 留言板")) {
			cl.show(this, "留言板");// 显示相应Panel
		} else if (str.startsWith("[ResShare, 最新排行")) {
			cl.show(this, "最新排行");// 显示相应Panel
		} else if (str.startsWith("[ResShare, 关于")) {
			cl.show(this, "关于");// 显示相应Panel
		} else
			cl.show(this, "搜索资源");// 显示相应Panel
	}
}
